package com.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exception.MyException;
import com.mapper.EpisodeMapper;
import com.mapper.PlayRecordMapper;
import com.model.Episode;
import com.model.PlayRecord;
import com.service.PlayRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 播放记录服务的实现接口
 */
@Service
public class PlayRecordServiceImpl extends ServiceImpl<PlayRecordMapper, PlayRecord> implements PlayRecordService {
    @Autowired
    private EpisodeMapper episodeMapper;

    @Override
    public boolean updatePlayRecord(int episodeId,int userId) {
        Episode episode=episodeMapper.selectById(episodeId);
        if(episode==null){
            throw new MyException(-1,"视频没有集的详细信息");
        }
        //生成播放记录对象并初始化
        PlayRecord playRecord=new PlayRecord();
        playRecord.setCreateTime(new Date());
        playRecord.setCurrentNum(episode.getNum());
        playRecord.setEpisodeId(episode.getId());
        playRecord.setUserId(userId);
        playRecord.setVideoId(episode.getVideoId());
        //插入数据库
        return save(playRecord);
    }

    @Override
    public PlayRecord findPalyRecByUserId(int userId) {
        return null;
    }
}
